﻿Imports DAO
Imports DTO

Public Class KhachHangBUS

    Public Function LayKhachHang() As DataTable
        Dim dt As New DataTable
        Dim kh As New KhachHangDAO
        dt = kh.LayKhachHang()
        Return dt
    End Function

    Public Function LayKhachHangNo() As DataTable
        Dim dt As New DataTable
        Dim kh As New KhachHangDAO
        dt = kh.LayKhachHangNo()
        Return dt
    End Function

    Public Function LayTenKhachHang(ByVal kh As KhachHangDTO) As DataTable
        Dim dt As New DataTable
        Dim khach As New KhachHangDAO
        dt = khach.layTenKhachHang(kh)
        Return dt
    End Function

    Public Sub ThemKhachHang(ByVal khachhang As KhachHangDTO)

        Dim qd As New QuyDinhDAO
        Dim dt As New DataTable
        dt = qd.LayQuyDinh()
        Dim dr As DataRow = dt.Rows(0)
        Dim tienno As Integer = Integer.Parse(dr.Item(3))
        If tienno < khachhang.LayTongNo Then
            Throw New Exception("Tiền nợ phải nhỏ hơn quy định.")
        End If
        Dim kh As New KhachHangDAO
        kh.ThemKhachHang(khachhang)
    End Sub

    Public Sub XoaKhachHang(ByVal khachhang As KhachHangDTO)
        Dim kh As New KhachHangDAO
        kh.XoaKhachHang(khachhang)
    End Sub

    Public Sub CapNhatKH(ByVal khachhang As KhachHangDTO)

        Dim qd As New QuyDinhDAO
        Dim dt As New DataTable
        dt = qd.LayQuyDinh()
        Dim dr As DataRow = dt.Rows(0)
        Dim tienno As Integer = Integer.Parse(dr.Item(3))
        If tienno < khachhang.LayTongNo Then
            Throw New Exception("Tiền nợ phải nhỏ hơn quy định.")
        End If

        Dim kh As New KhachHangDAO
        kh.updateKhachHang(khachhang)
    End Sub


    Public Sub UpDateNo(ByVal kh As KhachHangDTO, ByVal sl As Integer)
        Dim khach As New KhachHangDAO
        khach.updateNo(kh, sl)
    End Sub


    Public Function LayTienNo(ByVal kh As KhachHangDTO) As DataTable
        Dim khach As New KhachHangDAO
        Dim dt As New DataTable
        dt = khach.layTenKhachHang(kh)
        Return dt
    End Function
End Class
